<?php

namespace App\Http\Controllers;

use App\Services\PaymentService;

class PaymentController extends BaseController
{
    protected $paymentService;

    public function __construct()
    {
        $this->paymentService = new PaymentService();
    }

    /**
     * 结算
     */
    public function settlement(): \Illuminate\Http\JsonResponse
    {
        $this->uid = \session('uid');
        $time = \request()->input('time');
        $re = $this->paymentService->settlement($this->uid, $time);
        if( $re ){
            return returnJson(0, '', $re);
        }

        return returnJson(1, $this->paymentService->msg);
    }

    /**
     * 开通vip
     */
    public function openVip(): \Illuminate\Http\JsonResponse
    {
        $this->uid = \session('uid');
        $re = $this->paymentService->openVip($this->uid);
        if( $re ){
            return returnJson(0, '', $re);
        }

        return returnJson(1, $this->paymentService->msg);
    }

    /**
     * 提现
     */
    public function withdrawal(): \Illuminate\Http\JsonResponse
    {
        $this->uid = \session('uid');
        $amount = request()->input('amount');
        $re = $this->paymentService->withdrawal($this->uid, $amount);
        if( $re ){
            return returnJson();
        }

        return returnJson(1, $this->paymentService->msg);
    }
}
